package com.repair.order.pojo.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.repair.api.order.constant.OrderStatus;
import com.repair.datasource.entity.BaseEntity;
import com.repair.order.pojo.dto.OrderCreateParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * <p>
 * 订单
 * </p>
 *
 * @author 郑春雨
 * @since 2024-10-02
 */
@NoArgsConstructor
@Getter
@Setter
@TableName("repair_order")
@ApiModel(value = "Order对象", description = "订单")
public class Order extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("幂等号")
    @TableField("identifier")
    private String identifier;

    @ApiModelProperty("订单编号")
    @TableField("order_num")
    private String orderNum;

    @ApiModelProperty("上门地址")
    @TableField("order_address")
    private String orderAddress;

    @ApiModelProperty("订单价格")
    @TableField("order_price")
    private BigDecimal orderPrice;

    @ApiModelProperty("用户id")
    @TableField("user_id")
    private Long userId;

    @ApiModelProperty("用户昵称")
    @TableField("user_nick_name")
    private String userNickName;

    @ApiModelProperty("用户电话")
    @TableField("user_telephone")
    private String userTelephone;

    @ApiModelProperty("师傅id")
    @TableField("worker_id")
    private Long workerId;

    @ApiModelProperty("师傅姓名")
    @TableField("worker_nick_name")
    private String workerNickName;

    @ApiModelProperty("师傅电话")
    @TableField("worker_phone")
    private String workerPhone;

    @ApiModelProperty("订单状态(已派单、已拒接、已接单、待抢单、已抢单、维修中、待缴费、已完结、已取消、已评价、待处理、待接单、已支付)")
    @TableField("status")
    private String status;

    @ApiModelProperty("服务类型")
    @TableField("service_category_name")
    private String serviceCategoryName;

    @ApiModelProperty("服务类型id")
    @TableField("service_category_id")
    private Long serviceCategoryId;

    @ApiModelProperty("服务费")
    @TableField("service_price")
    private BigDecimal servicePrice;

    @ApiModelProperty("服务时间")
    @TableField("service_time")
    private LocalDateTime serviceTime;

    @ApiModelProperty("故障描述")
    @TableField("question_description")
    private String questionDescription;

    @ApiModelProperty("备注")
    @TableField("notes")
    private String notes;

    @ApiModelProperty("预约时间")
    @TableField("reserve_time")
    private LocalDateTime reserveTime;

    @ApiModelProperty("接单时间")
    @TableField("take_time")
    private LocalDateTime takeTime;

    @ApiModelProperty("施工前时间")
    @TableField("work_pre_time")
    private LocalDateTime workPreTime;

    @ApiModelProperty("施工前照片url")
    @TableField("work_pre_photo_url")
    private String workPrePhotoUrl;

    @ApiModelProperty("施工后时间")
    @TableField("work_after_time")
    private LocalDateTime workAfterTime;

    @ApiModelProperty("施工后照片url")
    @TableField("work_after_photo_url")
    private String workAfterPhotoUrl;

    @ApiModelProperty("支付时间")
    @TableField("pay_success_time")
    private LocalDateTime paySuccessTime;

    @ApiModelProperty("完成时间")
    @TableField("completion_time")
    private LocalDateTime completionTime;

    @ApiModelProperty("支付ID")
    @TableField("pay_id")
    private String payId;

    @ApiModelProperty("评价ID")
    @TableField("comment_id")
    private Long commentId;

    @ApiModelProperty("师傅公司名称")
    @TableField("company_name")
    private String companyName;

    @ApiModelProperty("材料ID")
    @TableField("material_id")
    private Long materialId;

    public Order(OrderCreateParam param, String orderNum, Long userId, String identifier) {
        this.identifier = identifier;
        this.orderNum = orderNum;
        this.orderAddress = param.getOrderAddress();
        this.notes = param.getNotes();
        this.userTelephone = param.getUserTelephone();
        this.userId = userId;
        this.reserveTime = param.getReserveTime();
        this.serviceCategoryId = param.getServiceCategoryId();
        this.status = OrderStatus.PENDING.name();
        this.serviceCategoryName = serviceCategoryName;
    }

    public Order(String orderNum, String name) {
        this.orderNum = orderNum;
        this.status = name;
    }

    public Order(String identifier) {
        this.identifier = identifier;
    }
}
